package com.example.Arithmetic.Lettcode;

import com.example.Arithmetic.Arithmetic.HashTable;
import org.junit.jupiter.api.Test;

import java.util.HashMap;

/**
 * 日期：2023/12/25
 * 时间：20:53
 * 描述：力扣第一题
 * 解题：从hash表中存，然后目标值减当前值，从hashtable表中获取减去值
 */
public class E01Lettcode1 {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer,Integer> map=new HashMap();
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            int i1 = target - num;
            if (map.containsKey(i1)){
                return new int[]{map.get(i1),i};
            }else {
                map.put(num,i);
            }
        }
        return null;
    }

    @Test
    public void tets(){
       int[] i=new int[]{2,7,11,15};
        int[] ints = twoSum(i,17);

        System.out.println(ints[0]);
        System.out.println(ints[1]);

    }

}

